(function(ns, win, doc, cfgs){
ns.addPlay(2, {
    Extends: ns.Play,
    options: {
        length: 1,
		sum: 7,
		allRequired: false
    },
    build: function(ops, self) {
        self.element = new Element('div');
        self.balls = [new ns.Balls({title: '选择号码', min: 1, max: 30, mid: 15, isBile: true})];
		self.balls[0].addControl(new ns.RandomControl({min: 7, max: 15}));
        self.balls.invoke('inject', self.element);
    },
    compute: function (balls) {
        var self = this,
            ops = self.options,
			ball = balls[0],
			total = ball.length.combination(ops.sum),
			info = {balls: ball.join(','), nums: ball.length, count: total};
			if ( ball.length > 15 ) info.count = 0;
        return info;
    },
    change: function () {
        var self = this,
            balls = self.balls.invoke('get');
            self.info = self.compute(balls);
        self.parent();
    },
    get: function (n, tpl) {
        var self = this,
            ops = self.options,
            suffix = self.suffix,
            len,
            balls,
            nums,
            info,
            html;
        if (n) {
            html = [];
            len = self.balls.length;
            while (n -- > 0) {
                nums = self.balls[0].random(ops.sum - 1).join(',');
                html.push(tpl({cost: ops.cost, type: ops.type, name: ops.name, count: 1, nums: nums, balls: nums}));
            }
            return html.join('');
        } else {
            balls = self.balls.invoke('get');
            info = self.compute(balls);
            return info.count > 0 ? tpl({cost: ops.cost, type: ops.type, name: ops.name, count: info.count, nums: info.balls, balls: info.balls}) : '';            
        }
    }
});


ns.addPlay(3, {
    Extends: ns.CombPlay,
    options: {
		randomType: 2,
        length: 1,
		sum: 8
    },
    build: function(ops, self) {
        self.element = new Element('div');
		self.balls = [new ns.BileBalls({title: '胆码', min: 1, max: 30, mid: 15, lower:1, upper: 6}), new ns.BileBalls({title: '拖码', min: 1, max: 30, mid: 15, lower: 2, upper: 30})];
        self.balls.invoke('inject', self.element);
    },

    get: function (n, tpl) {
        var self = this,
            ops = self.options,
            suffix = self.suffix,
            len,
            balls,
            nums,
            info,
            html;
        if (n) {
            html = [];
            len = self.balls.length;
            while (n -- > 0) {
				nums = self.balls[0].random(ops.sum - 1).join(',');
                html.push(tpl({cost: ops.cost, type: ops.randomType, name: cfgs.plays[ops.randomType].name, count: 1, nums: nums, balls: nums}));
            }
            return html.join('');
        } else {
            if (!self.validate()) {
                App.Alert('胆码加拖码至于要有' + ops.sum + '个');
                return '';
            }
            if (self.balls.invoke('check').every(function(r){return r;})) {
                balls = self.balls.invoke('get');
                info = self.compute(balls);
                return tpl({cost: ops.cost, type: ops.type, name: ops.name, count: info.count, nums: balls.invoke('join', ',').join('|'), balls: info.balls});                          
            }          
        }
    }
});

new ns.Lottery(cfgs.lottery);
})(using('HB'), this, document, this.configs || {});
